﻿<?php
//Pear & Propel Stuffs
set_include_path(get_include_path() .PATH_SEPARATOR. "../../../libs/pear");
set_include_path(get_include_path() .PATH_SEPARATOR. "../../../libs/propel/runtime/lib");
set_include_path(get_include_path() .PATH_SEPARATOR. "../../../bdd/build/classes");
require_once '../../../libs/propel/runtime/lib/Propel.php';
Propel::init("../../../bdd/build/conf/tshirtfactory-conf.php");

//Smarty stuffs
define('SMARTY_DIR', '../../../libs/');
require(SMARTY_DIR . 'Smarty.class.php');
$smarty = new Smarty;
$smarty->template_dir = '../../../pages/templates/';
$smarty->compile_dir = '../../../pages/templates_c/';
$smarty->config_dir = '../../../pages/configs/';
$smarty->cache_dir = '../../../pages/cache/';



$shirts = array();

if(isset($_GET['brands']))
{	
	//Search in description
	$querySearchDesc = ShirtQuery::create()->filterByDescription("*".$_GET['search']."*")->find();
	//Search in names
	$querySearchName = ShirtQuery::create()->filterByNom("%".$_GET['search']."%")->find();
	
	$ids = array();

	foreach($querySearchDesc as $s)
	{	
		array_push($ids, $s->getId());
	}
	
	foreach($querySearchName as $s)
	{
		array_push($ids, $s->getId());
	}
	
	$ids = array_unique($ids);

	$result = ShirtQuery::create()->filterById($ids)->filterByMarque($_GET['brands'])->filterByPrix(array('max' => $_GET['price']))->find();
	foreach($result as $s)
	{
		array_push($shirts, array("id" => $s->getId(), "title" => $s->getNom(), "price" => $s->getPrix(), "brand" => $s->getMarque(), "description" => $s->getDescription(), "material" => "Coton"));
	}
}
$smarty->assign("shirts", $shirts);
$smarty->display('shirt.tpl');